package com.jt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jt.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;

import java.util.List;
//@Mapper //为接口创建了反射机制的一个对象; ibatis可以通过Mapper管理接口,接口不能被new,new了也没用;
//MP规则:BaseMapper<T> MP要操作的表是谁? T要引入的就必须是谁.
public interface UserMapper extends BaseMapper<User> {
    //查询全部用户信息  访问修饰符  返回值类型 方法名(参数...)
    List<User> findAll();
    @Insert("insert into demo_user(id,name,age,sex) value(null,#{name},#{age},#{sex})")
    void insertUser(User user);
    @Update("update demo_user set name=#{newName} where name =#{oldName}")
    void updateByName(String oldName, String newName);
    //Mybatis中如果传递的参数只有一个,则名称任意,
    // "delete from demo_user where name=#{abc}"不会报错,但是一般不这样用.
    @Delete("delete from demo_user where name=#{name}")
    void deleteByName(String name);
    @Insert("insert into demo_user value(null,#{name},#{age},#{sex})")
    void insertUser2(User user);
    @Update("update demo_user set name=#{newName} where name =#{oldName}")
    void updateByName2(String newName, String oldName);
    @Delete("delete from demo_user where name=#{name}")
    void deleteByName2(String name);
}
